package com.beyondthewalls.components;

import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.component.Component;
import com.almasb.fxgl.physics.BoundingShape;
import com.almasb.fxgl.physics.HitBox;
import com.almasb.fxgl.physics.PhysicsComponent;
import com.almasb.fxgl.physics.SensorCollisionHandler;
import com.almasb.fxgl.physics.box2d.dynamics.BodyType;
import com.beyondthewalls.factories.ItemFactory;

public class Press extends Component {
    private final double width, height;
    private final int id;

    public Press(double width, double height, int id) {
        this.width = width;
        this.height = height;
        this.id = id;
    }

    @Override
    public void onAdded() {
        PhysicsComponent physics = new PhysicsComponent();
        physics.setBodyType(BodyType.STATIC);
        physics.addSensor(new HitBox(BoundingShape.box(width, height)),
                new SensorCollisionHandler() {
                    @Override
                    protected void onCollisionBegin(Entity other) {
                        ItemFactory.getMap().get(id).move();
                    }
                });

        entity.addComponent(physics);
    }
}
